using System.IO;

namespace Engine.FileFormats3D.C11Undercover.QADFile
{
    internal class Variable
    {
        #region Public Fields

        public uint data1;
        public uint data2;

        #endregion Public Fields

        #region Private Fields

        private char[] chars;

        #endregion Private Fields

        #region Internal Constructors

        internal Variable()
        {
        }

        #endregion Internal Constructors

        #region Public Methods

        public override string ToString()
        {
            string text = new string(this.chars);
            return string.Format(text + "\t {0}  \t  {1}", this.data1, this.data2);
        }

        #endregion Public Methods

        #region Internal Methods

        internal static Variable FromStream(BinaryReader br)
        {
            Variable variable = new Variable();
            long positionInFile = br.BaseStream.Position;

            int numberOfChars = 0;
            do
            {
                numberOfChars++;
            } while (br.ReadChar() != '\0');

            br.BaseStream.Position = positionInFile;
            variable.chars = br.ReadChars(numberOfChars);
            return variable;
        }

        internal void ToStream(BinaryWriter br)
        {
            br.Write(this.chars);
            //br.Write('\0');
        }

        #endregion Internal Methods
    }
}